package com.example.qlexpress.entity;

import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;

/**
 * @Author: whb
 * @Date: 2021/10/12 14:41
 * @Description
 */
public class BeanExample {
    public static String upper(String str) {
        System.out.println(str.toUpperCase());
        return str.toLowerCase();
    }

    public boolean anyContains(String str, String searchStr) {
        char[] chars = str.toCharArray();
        for (char aChar : chars) {
            System.out.println(aChar);
            if (searchStr.contains(aChar + ""))
                return true;
        }
        return false;
    }

    public static void main(String[] args) throws Exception {
        ExpressRunner runner = new ExpressRunner();
        runner.addFunctionOfClassMethod("取绝对值", Math.class.getName(), "abs", new String[]{"double"}, null);
        runner.addFunctionOfClassMethod("转换为大写", BeanExample.class.getName(), "upper", new String[]{"String"}, null);
        runner.addFunctionOfServiceMethod("打印", System.out, "println", new String[]{"String"}, null);
        runner.addFunctionOfServiceMethod("contains", new BeanExample(), "anyContains", new Class[]{String.class, String.class}, null);
        DefaultContext<String, Object> context = new DefaultContext<>();
        String exp = "取绝对值(-100);转换为大写(\"hello world\");打印(\"你好吗？\");contains(\"helloworld\",\"aeiou\")";
        Object execute = runner.execute(exp, context, null, false, false);
        System.out.println(execute);
    }
}
